package com.zhc.loom.oom;

/**
 * 说明：创建线程导致内存溢出异常
 * 		运行此代码的前提一定要保持当前的工作，执行时可能会导致操作系统假死。
 * VM Args: -Xss128k
 * @author jinsicao
 */
public class JavaVMStackOOM {
	
	int i = 0;

	private void dontStop() {
		while (true) {
			System.out.println(i++);
		}
	}
	
	public void stackLeakByThread() {
		while (true) {
			Thread thread = new Thread(new Runnable () {

				@Override
				public void run() {
					dontStop();
				}
				
			});
			thread.start();
		}
	}
	
	public static void main(String[] args) {
		JavaVMStackOOM oom = new JavaVMStackOOM();
		oom.stackLeakByThread();
	}
}
